import re

from browsermobproxy import Server
import os

os.system('taskkill /im java.exe')
os.system('taskkill /im java.exe')
os.system('taskkill /im java.exe')
os.system('taskkill /im java.exe')
server = Server(r"browsermob-proxy-2.1.4-bin\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
print(proxy.proxy)
chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy))
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])

driver = webdriver.Chrome(executable_path=r'chromedriver.exe',
                          options=chrome_options)

proxy.new_har("my_baidu", options={'captureHeaders': True, 'captureContent': True})

driver.get('###url')

import time

time.sleep(5)

result = proxy.har

with open('test.har', 'w', encoding='utf-8') as f:
    f.write(str(result))

for entry in result['log']['entries']:
    if (entry['request']['url']) == '###url':
        contentResult = entry['response']['content']['text']


os.system('taskkill /im java.exe')
os.system('taskkill /im java.exe')
